﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HYoloLabeler.Configs;
using YamlDotNet.Serialization;

namespace HYoloLabeler;
/// <summary>
/// Yaml配置管理
/// </summary>
public class YamlFileManager
{
    private readonly string filePath;

    public YamlFileManager(string filePath)
    {
        this.filePath = filePath;
    }
    /// <summary>
    /// 读取Yaml配置
    /// </summary>
    /// <returns></returns>
    public YOLOv8Config LoadYamlConfig()
    {
        var deserializer = new DeserializerBuilder().Build();
        using (var reader = new StreamReader(filePath))
        {
            return deserializer.Deserialize<YOLOv8Config>(reader);
        }
    }
    /// <summary>
    /// 保存Yaml配置
    /// </summary>
    /// <param name="config"></param>
    public void SaveYamlConfig(YOLOv8Config config)
    {
        var serializer = new SerializerBuilder().Build();
        using (var writer = new StreamWriter(filePath))
        {
            serializer.Serialize(writer, config);
        }
    }
}
